<?php
namespace app\admin\controller;
use think\Controller;
use think\Session;
class Login extends Controller
{
    public function index()
    {

    	// var_dump();
    	return $this->fetch();
    }

    public function checkdata()
    {
    	$username = input('post.username');
    	$password = md5(input('post.pass'));

    	$sql = "select * from admin where username=? and password =?";

    	$res = db()->query($sql,[$username,$password]);

    	if($res){

    		Session::set('username',$res[0]['username']);
    		Session::set('id',$res[0]['id']);

    		// $_SESSION['username']=$res[0]['username'];
    		// $_SESSION['id']=$res[0]['id'];

            $arr = array(
             'error'=>'0',
             'info'=>'登录成功'
             );
        }else{
            $arr = array(
             'error'=>'1',
             'info'=>'登录失败'
            );
        }
        echo json_encode($arr);
    }
    public function out()
    {
    	session::clear();
    	$this->success('退出成功','admin/login/index');
    }
}
